/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exatrez.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Mansur
 */
@Entity
@Table(name = "ship_visit")
@NamedQueries({
    @NamedQuery(name = "ShipVisit.findAll", query = "SELECT s FROM ShipVisit s")})
public class ShipVisit implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ship_visit_id")
    private Integer shipVisitId;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    private User user;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "vessel_id")
    private Vessel vessel;
    
    @Column(name = "date_visit")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateVisit;
    
    @Column(name = "location")
    private String location;
    
    @Column(name = "description")
    private String description;
    
    @Column(name = "delete_flag")
    private String deleted;
    
    @Embedded
    private InfoAudit infoAudit;
    
    @OneToMany (mappedBy = "shipVisit" , fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<ShipVisitFile> fileList;

    public ShipVisit() {
    }

    public ShipVisit(Integer shipVisitId) {
        this.shipVisitId = shipVisitId;
    }

    public Integer getShipVisitId() {
        return shipVisitId;
    }

    public void setShipVisitId(Integer shipVisitId) {
        this.shipVisitId = shipVisitId;
    }

    public Date getDateVisit() {
        return dateVisit;
    }

    public void setDateVisit(Date dateVisit) {
        this.dateVisit = dateVisit;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDeleted() {
        return deleted;
    }

    public void setDeleted(String deleted) {
        this.deleted = deleted;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Vessel getVessel() {
        return vessel;
    }

    public void setVessel(Vessel vessel) {
        this.vessel = vessel;
    }

    public InfoAudit getInfoAudit() {
        return infoAudit;
    }

    public void setInfoAudit(InfoAudit infoAudit) {
        this.infoAudit = infoAudit;
    }

    public List<ShipVisitFile> getFileList() {
        return fileList;
    }

    public void setFileList(List<ShipVisitFile> fileList) {
        this.fileList = fileList;
            }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (shipVisitId != null ? shipVisitId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ShipVisit)) {
            return false;
        }
        ShipVisit other = (ShipVisit) object;
        if ((this.shipVisitId == null && other.shipVisitId != null) || (this.shipVisitId != null && !this.shipVisitId.equals(other.shipVisitId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "exatrez.model.ShipVisit[ shipVisitId=" + shipVisitId + " ]";
    }
    
    public List<ShipVisitFile> getListFilteredFile(){
        List<ShipVisitFile> l = new ArrayList<ShipVisitFile>();
        for (ShipVisitFile svf : fileList) {
            if(svf.getDeleted().equals("N")){
                l.add(svf);
            }
        }
        return l;
    }
    
}
